<?php
require_once '../util/auth.php';
require_once("../db/${GLOBALS['__DBTYPE']}/get/user.php");

function loginDrone($name) {
    $user = getUserByPass($name,'');
    if( isset($user['id']) ) {
      $_SESSION['uid'] = $user['id'];
      unset($_SESSION['user']);
      $_SESSION['user']['name'] = $user['name'];
      $_SESSION['user']['ptree'] = getUserGrpTree( $user['permgrp'] );

      authorize($GLOBALS['__CFG']['AUTH_TIME']);
      $user = null;
      return true;

    } else {
      return false;
    }
}

function login($name, $pass) {
    $user = getUserByPass($name, hash('sha512',$pass));
    if( isset($user['id']) ) {
      $_SESSION['uid'] = $user['id'];
      unset($_SESSION['user']);
      $_SESSION['user']['name'] = $user['name'];
      $_SESSION['user']['ptree'] = getUserGrpTree( $user['permgrp'] );

      authorize($GLOBALS['__CFG']['AUTH_TIME']);

      $user = null;

      return true;
    } else {
      return false;
    }
}

?>
